<!DOCTYPE html>
<html>
<head>
    <title>模具位置关联</title>
    #parse("sys/header.html")
    <style>
        .sugon_upload_btn {
            display: -webkit-inline-box;
            display: inline-block;
        }
    </style>
</head>
<body>
<div id="rrapp" v-cloak>
    <div v-show="showList">
        <Row :gutter="16" style="margin: 8px 0px 0px 1px">
            <div class="search-group">
                <i-col span="3">
                    <i-input v-model="q.name" @on-enter="query" placeholder="备件名称"></i-input>
                </i-col>
                <i-col span="3">
                    <i-input v-model="q.positionNo" @on-enter="query" placeholder="位置号"></i-input>
                </i-col>
                <i-col span="3">
                    <i-select v-model="q.modType" placeholder="类型">
                        <i-option v-for="moldPositionType in moldPositionTypes" :value="moldPositionType"
                                  :key="moldPositionType">{{moldPositionType}}
                        </i-option>
                    </i-select>
                </i-col>
                <i-button @click="query">查询</i-button>
                <i-button @click="reloadSearch">重置</i-button>
            </div>
        </Row>
        <table id="jqGrid"></table>
    </div>
</div>
<script>
    var moldId = getQueryString("moldId")
    $(function () {
        $("#jqGrid").Grid({
            url: '../modulpositioncorrelation/list?moldId=' + moldId,
            rownumWidth: 35,
            colModel: [
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
                {label: '备件名称', name: 'positionName', index: 'POSITION_NAME', width: 120},
                {label: '位置号', name: 'positionNo', index: 'POSITION_NO', width: 70},
                {label: '特殊处理', name: 'positionRemark', index: 'POSITION_REMARK',width: 100},
                {label: '类型', name: 'modType', index: 'MOD_TYPE', width: 60},
                {label: '寿命标准', name: 'lifeStandard', index: 'LIFE_STANDARD', width: 60},
                {label: '最近一次更换时间',name: 'changeTime',index: 'CHANGE_TIME',width: 120},
                {label: '剩余寿命', name: 'residualLife', index: 'RESIDUAL_LIFE', width: 60, sortable: false},
                {
                    label: '当前次数', index: 'CURRENT_TIME', width: 60,
                    formatter: function (value, col, row) {
                        var stan = row.lifeStandard;
                        var currentTime = row.currentTime;
                        if (currentTime == null || currentTime == "" || stan == null || stan == "") {
                            return 0;
                        }
                        var ys = stan * 0.8;
                        if (currentTime < ys) {
                            return currentTime;
                        } else if (currentTime >= ys && currentTime <= stan) {
                            return '<span style="color: orange">' + currentTime + '</span>';
                        } else {
                            return '<span style="color: red">' + currentTime + '</span>';
                        }
                    }
                },
                {label: '换件数', name: 'setNum', hidden: true},
                {label: '规格', name: 'spec', hidden: true},
                {label: '适用型芯条码规则', name: 'barCodeRange', hidden: true},
                {name: 'currentTime', hidden: true}
            ]
        });
        vm.getMoldPositionTypes();
    });

    var vm = new Vue({
        el: '#rrapp',
        data: {
            showList: true,
            title: null,
            modulPositionCorrelation: {
                modType: '',
                estimateNum: '',
                lifeStandard: '',
                currentTime: '',
                replaceTimes: '',
                setNum: '',
                residualLife: '',
                changeTime: '',
                positionRemark: '',
                positionName: '',
                positionNo: '', // 位置号
                spec: '', // 规格
                modulCode: '',
                barCodeRange: '', // 适用型芯条码
                id: '',
            },
            ruleValidate: {
                positionName: [
                    {required: true, message: '备件名称必填', trigger: 'blur'}
                ],
                positionNo: [
                    {required: true, message: '位置号必填', trigger: 'blur'}
                ]
            },
            q: {
                name: '',
                positionNo: '', // 位置号
                modType: ''
            },
            moduleTypeList: enumsToList('MODULE_SPAREPART'), //模具 备件更换 镶块、型芯、镶件
            moldPositionTypes: []
        },
        methods: {
            getMoldPositionTypes: function () {
                // 获取备件单位
                Ajax.request({
                    url: '../modulpositioncorrelation/listUnit',
                    async: false,
                    successCallback: function (r) {
                        vm.moldPositionTypes = r.moldPositionTypes;
                    }
                });
            },
            query: function () {
                vm.reload();
            },
            getInfo: function (id) {
                Ajax.request({
                    url: "../modulpositioncorrelation/info/" + id,
                    async: true,
                    successCallback: function (r) {
                        vm.modulPositionCorrelation = r.modulPositionCorrelation;
                    }
                });
            },
            reload: function (event) {
                vm.showList = true;
                // 清空postData缓存数据
                var postData = $("#jqGrid").jqGrid("getGridParam", "postData");
                $.each(postData, function (k, v) {
                    delete postData[k];
                });
                // 构建查询参数
                var param = {};
                if (vm.q.name) {
                    param.name = vm.q.name;
                }
                if (vm.q.modType) {
                    param.modType = vm.q.modType;
                }
                if (vm.q.positionNo) {
                    param.positionNo = vm.q.positionNo;
                }
                var page = $("#jqGrid").jqGrid('getGridParam', 'page');
                $("#jqGrid").jqGrid('setGridParam', {
                    postData: param,
                    page: page
                }).trigger("reloadGrid");
                vm.handleReset('formValidate');
            },
            reloadSearch: function () {
                vm.q = {
                    name: '',
                    positionNo: '', // 位置号
                    modType: ''
                };
                vm.reload();
            }
        }
    });
    // 获取选中的模具位置ID列表
    var getSelectedPos = function () {
        return getSelectedRows("#jqGrid");
    }
</script>
</body>
</html>
